import 'package:flutter/material.dart';
import 'package:flutter_common_app/widgets/empty_view/v_empty_view.dart';
import 'package:loading_more_list/loading_more_list.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ListIndicator extends StatelessWidget {
  final IndicatorStatus indicatorStatus;
  final LoadingMoreBase loadingMoreBase;

  const ListIndicator(
    this.indicatorStatus,
    this.loadingMoreBase, {
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget widget;
    switch (indicatorStatus) {
      case IndicatorStatus.none:
        widget = Container(height: 0.0);
        break;
      case IndicatorStatus.loadingMoreBusying:
        widget = LoadingMoreBusying();
        break;
      case IndicatorStatus.fullScreenBusying:
        widget = LoadingMoreBusying();
        break;
      case IndicatorStatus.error:
        widget = errorWidget();
        break;
      case IndicatorStatus.fullScreenError:
        widget = errorWidget();
        break;
      case IndicatorStatus.noMoreLoad:
        widget = Center(
          child: Text('数据到底了'),
        );
        break;
      case IndicatorStatus.empty:
        widget = Center(
          child: Text('数据空'),
        );
        break;
    }
    return widget;
  }

  Widget errorWidget() {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Icon(Icons.error_outline),
              Text('加载出错，请重试'),
            ],
          ),
          VEmptyView(30.w),
          GestureDetector(
            onTap: (){
              loadingMoreBase.refresh(true);
            },
            child: Container(
              width: 200.w,
              height: 70.w,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [
                    Color.fromRGBO(236, 102, 84, 1),
                    Color.fromRGBO(234, 60, 42, 1),
                  ],
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                ),
                borderRadius: BorderRadius.all(
                  Radius.circular(100.w),
                ),
                border: Border.all(color: Colors.black12, width: 1),
              ),
              child: Text('重试',style: TextStyle(color: Colors.white,fontSize: 28.sp),),
            ),
          ),
        ],
      ),
    );
  }
}

class LoadingMoreBusying extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('加载中...'),
    );
  }
}
